/* ***** BEGIN LICENSE BLOCK *****
 * Version: MPL 1.1
 *
 * The contents of this file are subject to the Mozilla Public License Version
 * 1.1 (the "License"); you may not use this file except in compliance with
 * the License. You may obtain a copy of the License at
 * http://www.mozilla.org/MPL/
 *
 * Software distributed under the License is distributed on an "AS IS" basis,
 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
 * for the specific language governing rights and limitations under the
 * License.
 *
 * The Original Code is MaoBot.
 *
 * The Initial Developer of the Original Code is NoobSauce <tvilece@gmail.com>.
 * Portions created by NoobSauce are Copyright (C) 2011 NoobSauce. All Rights Reserved.
 *
 * Contributor(s):
 * tankgunk <tankgunk@gmail.com>
 *
 * ***** END LICENSE BLOCK ***** */
package org.maobot;

import java.util.ArrayList;
import java.util.Collections;

public class Deck extends Pile {
	private ArrayList<Card> arrangement = new ArrayList<Card>(0);
	Deck(){//make a single shuffled deck
		for(int i = 0; i <= 53; i++){
			arrangement.add(new Card(i));
			shuffle();
		}
	}
	Deck(int j){//make a deck filled with j complete sets of cards
		ArrayList<Card> t;	
		for(int k = 0; k < j; k++){
			t = new ArrayList<Card>(53);
			for(int i = 0; i <= 53; i++){
				t.add(new Card(i));
			}
			//arrangement.ensureCapacity(arrangement.size() + t.size() + 1);
			arrangement.addAll(t);
		}
	}
	public void trimToSize(){
		arrangement.trimToSize();
	}
	public void shuffle(){
		Collections.shuffle(arrangement);
	}
	public void shuffleIn(Card c){
		arrangement.add(c);
		shuffle();
	}
	public void shuffleIn(Pile d){
		arrangement.addAll(d.arrangement);
		d.arrangement = null;
		shuffle();
	}
	public Card draw(){
		if(arrangement.isEmpty()){
			shuffleIn(new Deck());
		}
		System.out.println("New deck shuffled in.");
		Card temp = arrangement.remove(0);
		if(arrangement.isEmpty()){
			System.out.println("Empty deck -- refill or it will be automatically refilled next draw");
		}
		return temp;
	}
	public void addBottom(Card c){
		arrangement.add(c);
	};
	public void addTop(Card c){
		arrangement.add(0, c);
	}

}
